package com.masterclient.app.modules.goods.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.masterclient.app.R;
import com.eoner.baselibrary.bean.goods.GoodDetailBean;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.masterclient.app.widget.FoldTextView;

import java.util.List;

/**
 * 作者：sean
 * 创建时间：2017/6/30 16:05
 * 功能说明：
 */

public class ServiceAdapter extends BaseAdapter implements FoldTextView.Callback{
    private List<GoodDetailBean.DataBean.ShServiceBean> list;
    private Context context;
    public ServiceAdapter(Context context, List<GoodDetailBean.DataBean.ShServiceBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = View.inflate(context, R.layout.item_fuwu,null);
        ImageView ivTag = view.findViewById(R.id.iv_tag);
        TextView tv = view.findViewById(R.id.tv_title);
        FoldTextView tv_sub = view.findViewById(R.id.tv_sub_title);
        GoodDetailBean.DataBean.ShServiceBean bean = list.get(position);
        ViewTransformUtil.glideImageView(context, bean.getSh_icon_url(), ivTag,0);
        tv.setText(bean.getSh_title());
        if (null != bean.getSh_desc()){
            tv_sub.setText(bean.getSh_desc(),false,this);
            tv_sub.setOnClickListener(view1 -> tv_sub.setChanged(true));
        }else {
            tv_sub.setText("",false,this);
        }
        tv_sub.configMaxLineCount(4);
        if (position == list.size()-1){
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tv_sub.getLayoutParams();
            params.bottomMargin = ScreenUtils.dp2px(70);
            tv_sub.setLayoutParams(params);
        }
        return view;
    }

    @Override
    public void onExpand() {

    }

    @Override
    public void onCollapse() {

    }

    @Override
    public void onLoss() {

    }
}
